<template>
<el-dialog
  title="上传文件"
  :visible.sync="centerDialogVisible"
  width="50%"
  center>
    <el-card>
      <el-upload
        class="upload-demo"
        ref="upload"
        drag
        action="fakeaction"
        :show-file-list="true"
        :http-request="uploadFn"
        :on-preview="handlePreview"
        :on-remove="handleRemove"
        :auto-upload="true">
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div slot="tip" class="el-upload__tip"></div>
      </el-upload>
      <!--<el-button style="margin-left: 10px;" size="small" type="success" @click="saveWaybillFile">确定</el-button>-->
    </el-card>
</el-dialog>

</template>

<script>
  import {ajax} from "@/store/yg/common/utils";
  import axios from "axios";
  import { untransform } from '@/store/yg/common/uri'
  import * as constant from '@/store/yg/common/constant';

  export default {
    props: [
  　　'row', 'data', 'more','channelType',"isDelete"
　  ],
    inject:['autoInitData'],
    data() {
      return {
        centerDialogVisible: false,
        fileTypeOptions:{

        },
        queryParams:{
          fileTypeId: "",
          fileName:"",
          tempFilename :'',
        },
        action:"",
        feeData:[],
        fileList: [{name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}, {name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'}]
      };
    },
    created: function () {
      this.action = constant.API_SERVER + "/api/consume/upload?uri=/amoeba/amoebaDiversCost/main&f=batchUploadAmoebaDiversCost&type=blank";
    },
    mounted() {
  },
    methods: {
      initFileTypeOptions(bean){
        var uri = "/api/entry/source?bean=" + bean;
        axios.post(constant.API_SERVER + uri).then(response => {
          this.fileTypeOptions = response.data;
          }, error => {
            console.info(error);
          }
          );
      },
      uploadFn(params){
          //自定义上传文件
        const file = params.file,
        fileType = file.type,
        isImage = fileType.indexOf("pdf") !== -1,
        isLt4M = file.size / 1024 / 1024 < 4;
        // 这里常规检验，看项目需求而定
       // if (!isImage) {
        //  this.$message.error("只能上传pdf格式!");
        //  return;
       // }

        //if (!isLt4M) {
       //   this.$message.error("只能上传图片大小小于4M");
       //   return;
      //  }
        console.log(this.param);
        const form = new FormData();
        // 文件对象
        form.append("items[]", file);

        /*ajax("batchUploadAmoebaChannelFormula", {"items[]": file}).then(
          res => {
            console.log(res);
          },
          error => {
            console.log(error);
          }
        );*/
        axios({
          method: "post",
          url: this.action,
          data: form
        }).then(response => {
          if (response.data.code === 200){
            console.log(response);
            this.$message.success("上传成功");
            this.timeout = setTimeout(() => {
              this.centerDialogVisible = false;
            }, 1000 * Math.random());
            this.autoInitData();
          }else{
            this.$notify.error({
              title: '错误',
              message: '上传失败!'+response.data.message
            });
          }
        }).catch(error => {
          console.log(error);
          this.$notify.error({
            title: '错误',
            message: '上传失败!'
          });
        })
    },
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },
    handlePreview(file) {
      console.log(file);
    },

    }
  }
</script>
